/**
 * LogKaiyuanFreezeService.java
 * Copyright(C) 1949++ 中华人民共和国
 * 深圳市盛开互联网金融顾问有限公司.
 * All rights reserved.
 * E-mail:server@skjr.net
 * SKDate:2017-11-16 17:28:58
 */
package com.huamao.zh.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.huamao.zh.base.PageWrapper;
import com.huamao.zh.constants.KaiyuanFreezeType;
import com.huamao.zh.mapper.LogKaiyuanFreezeMapper;
import com.huamao.zh.model.LogKaiyuanFreeze;
import com.huamao.zh.service.LogKaiyuanFreezeService;

@Service
@Transactional
public class LogKaiyuanFreezeServiceImpl implements LogKaiyuanFreezeService {

	@Autowired
	private LogKaiyuanFreezeMapper logKaiyuanFreezeMapper;

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuanFreeze add(LogKaiyuanFreeze logKaiyuanFreeze) throws Exception {
		logKaiyuanFreezeMapper.add(logKaiyuanFreeze);
		return logKaiyuanFreeze;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuanFreeze addSelective(LogKaiyuanFreeze logKaiyuanFreeze) throws Exception {
		logKaiyuanFreezeMapper.addSelective(logKaiyuanFreeze);
		return logKaiyuanFreeze;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int delete(Map<String, Object> map) {
		return logKaiyuanFreezeMapper.delete(map);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int update(LogKaiyuanFreeze logKaiyuanFreeze) throws Exception {
		return logKaiyuanFreezeMapper.update(logKaiyuanFreeze);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int updateSelective(LogKaiyuanFreeze logKaiyuanFreeze) throws Exception {
		return logKaiyuanFreezeMapper.updateSelective(logKaiyuanFreeze);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuanFreeze get(Integer id) {
		LogKaiyuanFreeze logKaiyuanFreeze = logKaiyuanFreezeMapper.get(id);
		return logKaiyuanFreeze;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public PageWrapper<LogKaiyuanFreeze> search(PageWrapper<LogKaiyuanFreeze> pageWrapper) {
		List<LogKaiyuanFreeze> logKaiyuanFreezes = logKaiyuanFreezeMapper.search(pageWrapper);
		pageWrapper.setList(logKaiyuanFreezes);
		return pageWrapper;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public List<LogKaiyuanFreeze> queryList(Map<String, Object> map) {
		return logKaiyuanFreezeMapper.queryList(map);
	}

	/**
	 * 功能说明：生成日志专用 Author：spring Date：2017/11/21 8:54
	 */
	public LogKaiyuanFreeze getLogKaiyuanFreeze(KaiyuanFreezeType type, int fromId, int userId, String orderNo,
			BigDecimal preKaiyuanFreeze, BigDecimal KaiyuanFreeze, String remark) {
		LogKaiyuanFreeze logKaiyuanFreeze = new LogKaiyuanFreeze();
		logKaiyuanFreeze.setType(type.getCode());
		logKaiyuanFreeze.setFromId(fromId);
		logKaiyuanFreeze.setUserId(userId);
		logKaiyuanFreeze.setOrderNo(orderNo);
		logKaiyuanFreeze.setPreKaiyuan(preKaiyuanFreeze);
		logKaiyuanFreeze.setKaiyuan(KaiyuanFreeze);
		logKaiyuanFreeze.setRemark(remark);
		logKaiyuanFreeze.setDataFlag(1);
		logKaiyuanFreeze.setCreateTime(new Date());
		return logKaiyuanFreeze;
	}

	/**
	 * 功能说明：添加 新增 流水 Author：spring Date：2017/11/21 8:56
	 */
	@Override
	public LogKaiyuanFreeze sumKaiyuanFreeze(KaiyuanFreezeType type, Integer fromId, Integer userId, String orderNo,
			BigDecimal preCash, BigDecimal cash, String remark) throws Exception {
		LogKaiyuanFreeze logKaiyuanFreeze = getLogKaiyuanFreeze(type, fromId, userId, orderNo, preCash, cash, remark);
		logKaiyuanFreeze.setKaiyuanType(1);
		return this.add(logKaiyuanFreeze);
	}

	/**
	 * 功能说明：添加 减少 流水 Author：spring Date：2017/11/21 8:56
	 */
	@Override
	public LogKaiyuanFreeze subtractKaiyuanFreeze(KaiyuanFreezeType type, Integer fromId, Integer userId,
			String orderNo, BigDecimal preCash, BigDecimal cash, String remark) throws Exception {
		LogKaiyuanFreeze logKaiyuanFreeze = getLogKaiyuanFreeze(type, fromId, userId, orderNo, preCash, cash, remark);
		logKaiyuanFreeze.setKaiyuanType(0);
		return this.add(logKaiyuanFreeze);
	}

}